﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace wicDIG
{
    public partial class CoordDialog : Form
    {
        public PointF coord;
        public CoordDialog()
        {
            InitializeComponent();
            txtRegion.Focus();
        }

        private void btOk_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
            coord = new PointF();
            
            if (txtRegion.Text != "")
            {
                string[] tcoord = txtRegion.Text.Split(' ');
                int gx, gy;
                if (tcoord.Length == 2)
                {
                    gx = int.Parse(tcoord[0]);
                    gy = int.Parse(tcoord[1]);
                }
                else
                {
                    gx = txtRegion.Text[1] - '0';
                    gy = txtRegion.Text[0] - '0';//row column format
                }


                coord.X = gx * UtilDig.GridInterval + UtilDig.GridOffset ;
                coord.Y = gy * UtilDig.GridInterval + UtilDig.GridOffset ;
            }
            else
            {
                coord.X = float.Parse(txtX.Text);
                coord.Y = float.Parse(txtY.Text);
            }
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void txtY_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
                btOk_Click(sender, e);
        }

        private void txtX_Enter(object sender, EventArgs e)
        {
            txtX.SelectAll();
        }
    }
}
